/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.ProductEntity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

@Entity
public class WeeklyMaterialRequirementEntity implements Serializable {
    @Id
    private String id;
    private Integer yearInt;
    private Integer monthInt;
    private Integer weekOfMonth;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date requestedOn;
    private String remarks;
    private String status;
    @ManyToOne
    private ProductEntity product;
    @OneToOne(mappedBy = "materialWeeklyRequirement")
    private PlannedWeeklyDemandEntity plannedWeeklyDemand; // planned weekly demand per product
    private double bomMultiplier; // BOM Multiplier = weeklyDemand * weight / bomBatchSize
    private double adjustedMultiplier;
    @OneToMany(mappedBy = "weeklyMaterialRequirement")
    private List<UnplannedMaterialRequirementEntity> unplannedMaterialRequirementEntities;
    private boolean purchased;
    private boolean raised;

    public WeeklyMaterialRequirementEntity() {
    }

    public WeeklyMaterialRequirementEntity(PlannedWeeklyDemandEntity plannedWeeklyDemand) {
        this.id = plannedWeeklyDemand.getId().replaceAll("PWD", "WMR");
        this.plannedWeeklyDemand = plannedWeeklyDemand;
        this.yearInt = plannedWeeklyDemand.getYearInt();
        this.monthInt = plannedWeeklyDemand.getMonthInt();
        this.weekOfMonth = plannedWeeklyDemand.getWeekOfMonth();
        this.bomMultiplier = plannedWeeklyDemand.getWeeklyDemand() * plannedWeeklyDemand.getProduct().getCaseWeight() / plannedWeeklyDemand.getProduct().getBOMEntity().getBatchSize();
        this.adjustedMultiplier = bomMultiplier;
        this.purchased = false;
        this.raised = false;
    }

    public ProductEntity getProduct() {
        return product;
    }

    public void setProduct(ProductEntity product) {
        this.product = product;
    }

    public List<UnplannedMaterialRequirementEntity> getUnplannedMaterialRequirementEntities() {
        return unplannedMaterialRequirementEntities;
    }

    public void setUnplannedMaterialRequirementEntities(List<UnplannedMaterialRequirementEntity> unplannedMaterialRequirementEntities) {
        this.unplannedMaterialRequirementEntities = unplannedMaterialRequirementEntities;
    }

    public boolean isPurchased() {
        return purchased;
    }

    public void setPurchased(boolean purchased) {
        this.purchased = purchased;
    }

    public boolean isRaised() {
        return raised;
    }

    public void setRaised(boolean raised) {
        this.raised = raised;
    }

    
    public Integer getMonthInt() {
        return monthInt;
    }

    public void setMonthInt(Integer monthInt) {
        this.monthInt = monthInt;
    }

    public Integer getWeekOfMonth() {
        return weekOfMonth;
    }

    public void setWeekOfMonth(Integer weekOfMonth) {
        this.weekOfMonth = weekOfMonth;
    }

    public Integer getYearInt() {
        return yearInt;
    }

    public double getAdjustedMultiplier() {
        return adjustedMultiplier;
    }

    public void setAdjustedMultiplier(double adjustedMultiplier) {
        this.adjustedMultiplier = adjustedMultiplier;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public Date getRequestedOn() {
        return requestedOn;
    }

    public void setRequestedOn(Date requestedOn) {
        this.requestedOn = requestedOn;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setYearInt(Integer yearInt) {
        this.yearInt = yearInt;
    }

    public double getBomMultiplier() {
        return bomMultiplier;
    }

    public void setBomMultiplier(double bomMultiplier) {
        this.bomMultiplier = bomMultiplier;
    }

    public PlannedWeeklyDemandEntity getPlannedWeeklyDemand() {
        return plannedWeeklyDemand;
    }

    public void setPlannedWeeklyDemand(PlannedWeeklyDemandEntity plannedWeeklyDemand) {
        this.plannedWeeklyDemand = plannedWeeklyDemand;
    }
    
    
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof WeeklyMaterialRequirementEntity)) {
            return false;
        }
        WeeklyMaterialRequirementEntity other = (WeeklyMaterialRequirementEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mrp.entities.MaterialWeeklyRequirementEntity[ id=" + id + " ]";
    }
    
}
